﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace WS.EKA.ServiceImpl
{
    public class BaseService<DBModel> where DBModel : class
    {
        public DBModel Get(params object[] keys)
        {
            var t = WS.EKA.DataAccess.DBContext<DBModel>.Get(keys);
            return t;
        }

        public List<DBModel> GetByPage(int pageIndex, int pageSize, Expression<Func<DBModel, bool>> filter
            , Func<IQueryable<DBModel>, IOrderedQueryable<DBModel>> order, out int recordTotal)
        {
            
            var t = WS.EKA.DataAccess.DBContext<DBModel>.GetByPage(pageIndex, pageSize, filter, order, out recordTotal);
            return t;
        }

        public List<DBModel> GetByPage<TKey>(int pageIndex, int pageSize, Expression<Func<DBModel, bool>> filter
            , Expression<Func<DBModel, TKey>> order, bool desc, out int recordTotal)
        {
            var t = WS.EKA.DataAccess.DBContext<DBModel>.GetByPage(pageIndex, pageSize, filter, order, desc, out recordTotal);
            return t;
        }

        public virtual void Delete(Expression<Func<DBModel, bool>> filter)
        {
            WS.EKA.DataAccess.DBContext<DBModel>.Delete(filter);
        }
        public virtual void Delete(int id)
        { 
            
        }

        public DBModel Get(Expression<Func<DBModel, bool>> filter, Func<IQueryable<DBModel>, IOrderedQueryable<DBModel>> orderBy = null)
        {
            var t = WS.EKA.DataAccess.DBContext<DBModel>.Get(filter, orderBy);
            return t;
        }
     
    }
}
